/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.ac.cput.DesignPatterns.structural.FlyWeight;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author 210017252
 */
public class FlyWeightFactory {
    
public static FlyWeightFactory flyWeightFactory;
private Map<String,FlyWeight> flyweightPool;

    public FlyWeightFactory() {
    flyweightPool=new HashMap<String,FlyWeight>();
    
    }
public static FlyWeightFactory getInstance(){

    if(flyWeightFactory==null){
flyWeightFactory =new FlyWeightFactory();
}
    return flyWeightFactory;
}
public FlyWeight getFlightWeight(String key){

    if(flyweightPool.containsKey(key)){
    
        return flyweightPool.get(key);
    }else{
    FlyWeight flyWeight; 
    if("add".equals(key)){
    flyWeight= new FlyWeightAdder();
    }else{
    flyWeight= new FlyWeightMultiplier();
    } 
    flyweightPool.put(key, flyWeight);
    return flyWeight;
    }
    
}


}
